<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:72:"/data/wwwroot/luckyDraw/m/public/../application/view/bindphone/pages.php";i:1495175534;}*/ ?>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
    <title>绑定手机号码</title>
    <link rel="stylesheet" href="<?php echo \think\Config::get('style'); ?>/wx/css/bootstrap.css">
    <link rel="stylesheet" href="<?php echo \think\Config::get('style'); ?>/wx/css/font-awesome.css">
    <link rel="stylesheet" href="<?php echo \think\Config::get('style'); ?>/wx/css/cl-style.css">
    <script type="text/javascript" src="<?php echo \think\Config::get('style'); ?>/wx/js/jquery-1.11.3.min.js"></script>
</head>
<body>

<div class="container-fluid">
    <div class="row">
        <header class="cl-Forgetpasswd-header">
            <ul>
                <li class="col-xs-3"></li>
                <li class="col-xs-6 text-center"><span class="text-center">绑定手机号码</span></li>
                <li class="col-xs-3"></li>
            </ul>
        </header>
        <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">

        </div>

        <div class="cl-VerifyKey-main">
            <form>
                <div class="form-group">
                    <ul class="row">
                        <li class="col-xs-12">
                            <label for="Newpassword" class="sr-only">序列号</label>
                            <div class="input-group">
                                <span class="input-group-addon cl-lnput-icon"><i class="fa fa-barcode fa-lg"></i></span>
                                <input type="text" class="form-control" id="yanzhengma" name="phone" size="12" placeholder="请输入您的手机号码">
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="form-group">
                    <label for="yanzhengma" class="sr-only">验证码</label>

                    <div class="input-group">

                        <input type="text" class="form-control" name="phone_code" id="phone_code" placeholder="输入验证码" onkeyup="ajax_yanzhengma()">

                        <span class="input-group-addon">
                               <a id="get_code">点击获取</a>

                            </span>
                    </div>
                </div>
                <div class="form-group">
                    <button type="button" class="btn btn-block btn-warning" onclick="CheckLPNO();">绑定</button><!---  状态成功后disabled标签被删除 ---->
                </div>

            </form>

        </div>
    </div>
</div>

</body>
<script>
    function CheckLPNO(){
        if((/^1[34578]\d{9}$/.test($('#yanzhengma').val()))){
            if(!(/[0123456789]{6}$/.test($('#phone_code').val()))){
                alert('验证码错误1');
                alert($('#get_code').val());
                return false;
            }
            var url="<?php echo url('Bindphone/checkPhone'); ?>";
            var datastr="phone="+$.trim($("#yanzhengma").val())+"&phone_code="+$.trim($("#phone_code").val());
            $.ajax({
                url: url,
                data: datastr,
                type: "POST",
                dataType: "json",
                success: function(data) {
                    if (data.status==1) {
                        window.location="<?php echo $url; ?>";
                    }else{
                        alert(data.message);
                    }
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    alert('绑定手机号码失败'+XMLHttpRequest.readyState);
                }
            })
        }else{
            alert('手机号错误,请核查!');
        }
    }

    var count=0;
    var sum = 60;
    //获得手机验证码
    $('#get_code').click(function() {
        var num=$('#yanzhengma').val().length;
        if( num<11 || num>11 ){
            return false;
        }
        if(count>0 && count<=60){
            return false;
        }
        var send_obj = $(this);
        var url = "<?php echo url('Bindphone/getCode'); ?>";
        var datastr = "phone=" + $.trim($("#yanzhengma").val());
        $.ajax({
            url: url,
            data: datastr,
            type: "POST",
            dataType: "json",
            success: function(data) {
                if(data.status==1){
                    //60秒后重新启动发送按钮
                    var i = setInterval(function() {
                        if (count > sum) {
                            send_obj.html('发送验证码');
                            clearInterval(i);
                        } else {
                            send_obj.html('剩余' + parseInt(sum - count) + '秒');
                        }
                        count++;
                    }, 1000);
                    count=0;
                }else{
                    alert(data.msg);
                }
            }
        });
    });
</script>
</html>